package com.javacoo.swing.jxbrowser.engine;

import com.javacoo.swing.jxbrowser.BaseBrowser;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserContext;
import com.teamdev.jxbrowser.chromium.BrowserContextParams;

/**
 * 清除缓存
 * <li></li>
 * 默认情况下，Chromium引擎中启用了缓存。持久性缓存数据存储在Chromium数据目录的Cache文件夹中。例如，c：\ Users \ <用户名> \ AppData \ Local \ JxBrowser \ jxbrowser-chromium-43.0.2357.52.6.2 \ data \ Cache
 * Chromium API根本不提供允许禁用缓存的功能，但它提供了允许清除缓存存储的功能。以下示例演示如何使用JxBrowser Cache API清除持久性缓存存储
 * @author: duanyong@jccfc.com
 * @since: 2020/9/24 9:09
 */
public class ClearingCache extends BaseBrowser {
    public static void main(String[] args) {
        BrowserContext context1 = new BrowserContext(new BrowserContextParams("C:\\my-data1"));
        Browser browser1 = new Browser(context1);
        Browser browser2 = new Browser(context1);

        BrowserContext context2 = new BrowserContext(new BrowserContextParams("C:\\my-data2"));
        Browser browser3 = new Browser(context2);

        // Clears cache of browser1 and browser2 instances because they use the same
        // user data and cache "C:\\my-data1" directory. It doesn't clear cache
        // of browser3, because browser3 uses a different directory for storing
        // cache data - "C:\\my-data2".
        browser1.getCacheStorage().clearCache();
    }
}
